home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / instring / form23.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-05-05  |  2.7 KB  |  91 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   3525
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   5175
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3525
  10.    ScaleWidth      =   5175
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.TextBox Text2 
  13.       Height          =   495
  14.       Left            =   1680
  15.       TabIndex        =   5
  16.       Text            =   "ashaMuralidhar"
  17.       Top             =   360
  18.       Width           =   1815
  19.    End
  20.    Begin VB.CommandButton Command2 
  21.       Caption         =   "Close"
  22.       Height          =   495
  23.       Left            =   3360
  24.       TabIndex        =   4
  25.       Top             =   2760
  26.       Width           =   1215
  27.    End
  28.    Begin VB.CommandButton Command1 
  29.       Caption         =   "Find"
  30.       Height          =   495
  31.       Left            =   1800
  32.       TabIndex        =   1
  33.       Top             =   1800
  34.       Width           =   1455
  35.    End
  36.    Begin VB.TextBox Text1 
  37.       Height          =   495
  38.       Left            =   1920
  39.       TabIndex        =   0
  40.       Top             =   1080
  41.       Width           =   1215
  42.    End
  43.    Begin VB.Label Label2 
  44.       Caption         =   "Main String"
  45.       Height          =   375
  46.       Left            =   600
  47.       TabIndex        =   3
  48.       Top             =   360
  49.       Width           =   1095
  50.    End
  51.    Begin VB.Label Label1 
  52.       Caption         =   "Find string"
  53.       Height          =   375
  54.       Left            =   720
  55.       TabIndex        =   2
  56.       Top             =   1080
  57.       Width           =   975
  58.    End
  59. Attribute VB_Name = "Form1"
  60. Attribute VB_GlobalNameSpace = False
  61. Attribute VB_Creatable = False
  62. Attribute VB_PredeclaredId = True
  63. Attribute VB_Exposed = False
  64. Option Explicit
  65. Dim Pos As Integer, temp As String, ctr As Integer
  66. Private Sub Command1_Click()
  67. ' Counts the number of occurances of the string
  68. ctr = 0
  69. ' gives the position aof the string
  70. Pos = 0
  71. If Len(Text1.Text) = 0 Then
  72. MsgBox "Enter String to be found"
  73. If Len(Text2.Text) = 0 Then
  74. MsgBox "Enter String to be searched in"
  75. temp = Text2.Text ' temporary variable
  76. ' the loop sees if there are more than one occurance of a string/words in a string
  77. Pos = InStr(temp, Text1.Text) 'finds the substring in the string
  78. If Pos = 0 Then ' string not found in main string
  79. Exit Do
  80. End If
  81. ctr = ctr + 1 ' count the number of occurances
  82. temp = Right(temp, Len(temp) - Pos)
  83. Loop While (ctr > 0 And Len(temp) > Len(Text1.Text))
  84. MsgBox ctr ' displays the number of occurances
  85. End If
  86. End If
  87. End Sub
  88. Private Sub Command2_Click()
  89. Unload Me
  90. End Sub
  91.